package com.leetcode.partition9;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/12/21 10:15
 */
public class LC805数组的均值分割 {

    public static boolean splitArraySameAverage(int[] nums) {
        //TODO TLE
        int n = nums.length, sum = Arrays.stream(nums).sum();
        float avg = sum / (float) n;
        for (int i = 0; i < 1 << n; i++) {
            int sumA = 0, countA = Integer.bitCount(i);
            for (int j = 0; j < n; j++) {
                if ((i >> j & 1) == 1) {
                    sumA += nums[j];
                }
            }
            int sumB = sum - sumA, countB = n - countA;
            if (sumA / (float) countA == sumB / (float) countB) return true;
        }
        return false;
    }

    public static void main(String[] args) {
//        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8};
//        int[] nums = {2, 0, 5, 6, 16, 12, 15, 12, 4};
//        int[] nums = {3, 1};
        int[] nums = {60, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
                30, 30, 30, 30};
        System.out.println(splitArraySameAverage(nums));

//        int j = 0;
//        for (int i = 0; i < 1 << 30; i++) j++;
//        System.out.println("ss");
    }
}
